﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.franchise.display {
    import flash.display.*;
    import org.aswing.*;
    import org.aswing.event.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class FranchiseCardScrollingList extends JPanel {

        public static const NUM_ITEMS:int = 4;
        protected static const ROW_HEIGHT:int = 59;
        protected static const ROW_WIDTH:int = 659;

        protected var m_model:VectorListModel;
        protected var m_columns:int;
        protected var m_rows:int;
        protected var m_cellFactory:GridListCellFactory;
        protected var m_data:Array;
        protected var m_dataList:GridList;
        protected var m_scrollPane:JScrollPane;
        protected var m_navPane:JPanel;
        protected var upButton:JButton;
        protected var downButton:JButton;
        protected var m_curCount:int = 0;
        protected var m_curIndex:int = 0;

        public function FranchiseCardScrollingList(_arg1:Array, _arg2:Class, _arg3:int, _arg4:int=0, _arg5:int=1){
            super(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 0, SoftBoxLayout.LEFT));
            this.m_cellFactory = new (_arg2)();
            this.m_columns = _arg4;
            this.m_rows = _arg5;
            this.m_data = _arg1;
            this.makeCards();
            this.makeButtons();
            this.makeNavPane();
            this.append(this.m_scrollPane);
            this.append(ASwingHelper.horizontalStrut(3));
            this.append(this.m_navPane);
            this.setPreferredWidth(ROW_WIDTH);
            this.setMinimumWidth(ROW_WIDTH);
            this.setMaximumWidth(ROW_WIDTH);
            ASwingHelper.prepare(this);
        }
        protected function makeCards():void{
            this.m_model = new VectorListModel();
            var _local1:int = Math.min(NUM_ITEMS, this.m_data.length);
            var _local2:int;
            while (_local2 < _local1) {
                this.m_model.append(this.m_data[_local2]);
                this.m_curCount++;
                _local2++;
            };
            this.m_dataList = new GridList(this.m_model, this.m_cellFactory, 1, 0);
            this.m_dataList.setVGap(0);
            this.m_scrollPane = new JScrollPane(this.m_dataList, JScrollPane.SCROLLBAR_NEVER, JScrollPane.SCROLLBAR_NEVER);
        }
        protected function makeButtons():void{
            var _local1:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_up_normal"])() as DisplayObject);
            var _local2:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_up_down"])() as DisplayObject);
            var _local3:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_up_over"])() as DisplayObject);
            var _local4:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_down_normal"])() as DisplayObject);
            var _local5:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_down_down"])() as DisplayObject);
            var _local6:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_down_over"])() as DisplayObject);
            this.upButton = new JButton();
            this.upButton.wrapSimpleButton(new SimpleButton(_local1, _local3, _local2, _local1));
            this.upButton.setEnabled(false);
            this.downButton = new JButton();
            this.downButton.wrapSimpleButton(new SimpleButton(_local4, _local6, _local5, _local4));
            if (this.m_data.length <= NUM_ITEMS){
                this.downButton.setEnabled(false);
            } else {
                this.downButton.setEnabled(true);
            };
            this.upButton.addActionListener(this.moveUp, 0, true);
            this.downButton.addActionListener(this.moveDown, 0, true);
        }
        protected function makeNavPane():void{
            this.m_navPane = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
            this.m_navPane.append(this.upButton);
            this.m_navPane.appendAll(ASwingHelper.verticalStrut(150));
            this.m_navPane.append(this.downButton);
            ASwingHelper.prepare(this.m_navPane);
        }
        protected function moveUp(_arg1:AWEvent):void{
            this.m_curIndex = (this.m_curIndex - NUM_ITEMS);
            if (this.m_curIndex <= 0){
                this.upButton.setEnabled(false);
                this.m_curIndex = 0;
            };
            this.m_dataList.scrollVertical((-(ROW_HEIGHT) * NUM_ITEMS));
            this.downButton.setEnabled(true);
        }
        public function get currentItem():int{
            return ((this.m_curIndex - NUM_ITEMS));
        }
        protected function moveDown(_arg1:AWEvent):void{
            var _local4:int;
            var _local2:int = this.m_curCount;
            var _local3:int = Math.min(this.m_data.length, (this.m_curCount + NUM_ITEMS));
            if ((_local3 - _local2) > 0){
                if (this.m_model.getSize() < (NUM_ITEMS + this.m_curCount)){
                    _local4 = _local2;
                    while (_local4 < _local3) {
                        this.m_model.append(this.m_data[_local4]);
                        this.m_curCount++;
                        this.m_curIndex++;
                        _local4++;
                    };
                    if ((this.m_curIndex + NUM_ITEMS) >= (this.m_data.length - 1)){
                        this.downButton.setEnabled(false);
                    };
                };
            } else {
                if (this.m_curIndex < this.m_curCount){
                    this.m_curIndex = (this.m_curIndex + NUM_ITEMS);
                    if ((this.m_curIndex + NUM_ITEMS) >= (this.m_data.length - 1)){
                        this.downButton.setEnabled(false);
                    };
                };
            };
            this.upButton.setEnabled(true);
            this.m_dataList.scrollVertical((ROW_HEIGHT * NUM_ITEMS));
        }

    }
}//package Modules.franchise.display 
